home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / cmdlg7.zip / PORT_.PAS < prev    next >
Pascal/Delphi Source File  |  1992-12-10  |  7KB  |  409 lines

  1. {µµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµ}
  2. {   \\\                                    }
  3. {  -(j)-                                   }
  4. {    /juanca «                             }
  5. {    ~                                     }
  6. {   ⌐ ACASA 1989-1992, All rights reserved }
  7. {µµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµµ}
  8.  
  9. { an OO shell for DeviceContext, place in your tPort Object any method
  10. that makes your life with GDI easier
  11. }
  12.  
  13. UNIT PORT_;
  14. {$C MOVEABLE DEMANDLOAD DISCARDABLE}
  15. INTERFACE
  16.    USES
  17.      OBJECTS,
  18.      OWINDOWS,
  19.      WINTYPES;
  20.  
  21.    CONST
  22.      NULL = 0;
  23.  
  24.    TYPE
  25.      TPolyPoints = array[0..MaxInt div 4] of TPoint;
  26.      PPolyPoints = ^TPolyPoints;
  27.  
  28.      PPort = ^TPort;
  29.      Super      = TObject;
  30.      TPort = OBJECT (Super)
  31.        CONSTRUCTOR
  32.          init;
  33.        CONSTRUCTOR
  34.          initD(hdev:THandle);
  35.        CONSTRUCTOR
  36.          initGet(iwin:PWindowsObject); { get the DeviceContext from a tWindow }
  37.        CONSTRUCTOR
  38.          compatible(dc:PPort);
  39.  
  40.        DESTRUCTOR
  41.          done;
  42.            virtual;
  43.        DESTRUCTOR
  44.          delete;
  45.            virtual;
  46.  
  47.  
  48.        FUNCTION
  49.          context:THandle;
  50.            virtual;
  51.        PROCEDURE
  52.          set_context( newHDC:THandle);
  53.  
  54.        FUNCTION
  55.        isPrinter :Boolean;  { always FALSE, tPrinter returns TRUE }
  56.  
  57.        FUNCTION
  58.        cycle :Boolean;
  59.          virtual;
  60.                               { function to call from long painting routines,
  61.                               it exists so when painting to a tPrinter,
  62.                               user can interruput with the PrintAbort dlg
  63.                               }
  64.  
  65.        FUNCTION
  66.          select(obj :THandle):THandle;
  67.  
  68.        FUNCTION
  69.          textOut(x, y:Integer; txt:pChar):Boolean;
  70.  
  71.        PROCEDURE
  72.          setPixel(x, y :Integer; color :TColorRef);
  73.  
  74.        PROCEDURE
  75.          moveTo(x, y:Integer);
  76.        PROCEDURE
  77.          lineTo(x, y:Integer);
  78.  
  79.        FUNCTION
  80.          rectangle(x1, y1, x2, y2:Integer):Boolean;
  81.  
  82.        FUNCTION
  83.          ellipse(x1, y1, x2, y2:Integer):Boolean;
  84.  
  85.        FUNCTION
  86.          polyLine(var points :TPolyPoints; count :Word):Boolean;
  87.  
  88.        FUNCTION
  89.          polygon(var points :TPolyPoints; count :Word):Boolean;
  90.  
  91.        PROCEDURE
  92.          lp2dp(var points; count:Word);
  93.        PROCEDURE
  94.          dp2lp(var points; count:Word);
  95.  
  96.        FUNCTION
  97.          compatibleBitmap(w, h :Integer):HBitmap;
  98.  
  99.        PROCEDURE
  100.          save;
  101.        PROCEDURE
  102.          restore;
  103.  
  104.        FUNCTION
  105.          setROP2(mode:Integer):Integer;
  106.  
  107.  
  108.        FUNCTION
  109.        mapMode :Integer;
  110.  
  111.        PROCEDURE
  112.        setMapMode(mm :Integer);
  113.  
  114.        PROCEDURE
  115.        textExtents(s :pChar; var width, height :Word);
  116.  
  117.  
  118.      PRIVATE
  119.        _hdc : THandle;
  120.        _win : PWindowsObject;
  121.      END;{OBJECT Super}
  122.  
  123.  
  124.  
  125.  
  126. {@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@}
  127. IMPLEMENTATION
  128.   USES
  129.     WINPROCS,
  130.     STRINGS;
  131.  
  132.   CONST
  133.     mm_DivFactor = 1;
  134.  
  135.   PROCEDURE
  136.   {}
  137.   softYield;
  138.     var
  139.      msg :tMsg;
  140.     begin
  141.       peekMessage(msg, 0, 0, Word(-1), pm_NoRemove)
  142.     end;
  143.  
  144.   CONSTRUCTOR
  145.   TPort.
  146.     {}
  147.   init;
  148.     begin
  149.       Super.init;
  150.       _win := nil;
  151.       _hdc := null
  152.     end;
  153.  
  154.   CONSTRUCTOR
  155.   TPort.
  156.     {}
  157.   initD(hdev:THandle);
  158.     begin
  159.       Super.init;
  160.       _win := nil;
  161.       _hdc := hdev
  162.     end;
  163.  
  164.   CONSTRUCTOR
  165.   TPort.
  166.     {}
  167.   initGet(iwin :PWindowsObject);
  168.     begin
  169.       Super.init;
  170.       _win := iwin;
  171.       if _win <> nil then
  172.         _hdc := getDC(_win^.hwindow)
  173.       else
  174.         _hdc := null
  175.     end;
  176.  
  177.   CONSTRUCTOR
  178.   TPort.
  179.     {}
  180.   compatible(dc:PPort);
  181.     begin
  182.       Self.initD(createCompatibleDC(dc^.context));
  183.     end;
  184.  
  185.  
  186.   DESTRUCTOR
  187.   TPort.
  188.     {}
  189.   done;
  190.     begin
  191.       if _win <> nil
  192.       then
  193.         releaseDC(_win^.hwindow, context);
  194.       _win := nil;
  195.       _hdc := null
  196.     end;
  197.  
  198.   DESTRUCTOR
  199.   TPort.
  200.     {}
  201.   delete;
  202.     begin
  203.        if _hdc <> null
  204.        then
  205.          deleteDC(_hdc);
  206.       _win := nil;
  207.       _hdc := null
  208.     end;
  209.  
  210.   FUNCTION
  211.   TPort.
  212.     {}
  213.   context:THandle;
  214.     begin
  215.       context := _hdc
  216.     end;
  217.  
  218.   PROCEDURE
  219.   TPort.
  220.     {}
  221.   set_context(newHDC :THandle);
  222.     begin
  223.       _hdc := newHDC;
  224.       _win := nil
  225.     end;
  226.  
  227.   FUNCTION
  228.   tPort.
  229.   {}
  230.   isPrinter :Boolean;
  231.     begin
  232.       isPrinter := FALSE
  233.     end;
  234.  
  235.   FUNCTION
  236.   TPort.
  237.     {}
  238.   cycle:Boolean;
  239.     begin
  240.       cycle := TRUE;
  241.       softYield
  242.     end;
  243.  
  244.   {}
  245.   {}
  246.   FUNCTION
  247.   TPort.
  248.     {}
  249.   select(obj :THandle):THandle;
  250.     begin
  251.       select := selectObject(context, obj)
  252.     end;
  253.  
  254.   {}
  255.   {}
  256.   PROCEDURE
  257.   TPort.
  258.     {}
  259.   setPixel(x, y :Integer; color :TColorRef);
  260.     begin
  261.       WinProcs.setPixel(context, x, y, color)
  262.     end;
  263.  
  264.   {}
  265.   {}
  266.   PROCEDURE
  267.   TPort.
  268.     {}
  269.   moveTo(x, y:Integer);
  270.     begin
  271.       WinProcs.moveTo(context, x, y)
  272.     end;
  273.  
  274.   {}
  275.   {}
  276.   PROCEDURE
  277.   TPort.
  278.     {}
  279.   lineTo(x, y:Integer);
  280.     begin
  281.       WinProcs.lineTo(context, x, y)
  282.     end;
  283.  
  284.   FUNCTION
  285.   TPort.
  286.     {}
  287.   rectangle(x1, y1, x2, y2:Integer):Boolean;
  288.     begin
  289.       rectangle := Word(WinProcs.rectangle(context, x1, y1, x2, y2)) <> 0
  290.     end;
  291.  
  292.   {}
  293.   {}
  294.   FUNCTION
  295.   TPort.
  296.     {}
  297.   ellipse(x1, y1, x2, y2:Integer):Boolean;
  298.     begin
  299.       ellipse := Word(WinProcs.ellipse(context, x1, y1, x2, y2)) <> 0
  300.     end;
  301.  
  302.   FUNCTION
  303.   TPort.
  304.     {}
  305.   polygon(var points :TPolyPoints; count :Word):Boolean;
  306.     begin
  307.       polygon := 0 <> Word(WINPROCS.polygon(context, points, count))
  308.     end;
  309.  
  310.  
  311.   FUNCTION
  312.   TPort.
  313.     {}
  314.   polyLine(var points :TPolyPoints; count :Word):Boolean;
  315.     begin
  316.       polyLine := 0 <> Word(WINPROCS.polyLine(context, points, count))
  317.     end;
  318.  
  319.  
  320.   {}
  321.   {}
  322.   FUNCTION
  323.   TPort.
  324.     {}
  325.   textOut(x, y:Integer; txt:pChar):Boolean;
  326.     begin
  327.       textOut := 0 <> Word(WinProcs.textOut(context, x, y, txt, strLen(txt)));
  328.     end;
  329.  
  330.   PROCEDURE
  331.   TPort.
  332.     {}
  333.   lp2dp(var points; count:Word);
  334.     begin
  335.       LPToDP(context, points, count)
  336.     end;
  337.  
  338.   PROCEDURE
  339.   TPort.
  340.     {}
  341.   dp2lp(var points; count:Word);
  342.     begin
  343.       DPToLP(context, points, count)
  344.     end;
  345.  
  346.   FUNCTION
  347.   TPort.
  348.     {}
  349.   compatibleBitmap(w, h :Integer):HBitmap;
  350.     begin
  351.       compatibleBitmap := createCompatibleBitmap(context, w, h)
  352.     end;
  353.  
  354.   PROCEDURE
  355.   TPort.
  356.     {}
  357.   save;
  358.     begin
  359.       saveDC(context);
  360.     end;
  361.  
  362.   PROCEDURE
  363.   TPort.
  364.    {}
  365.   restore;
  366.     begin
  367.       restoreDC(context, -1)
  368.     end;
  369.  
  370.  
  371.   FUNCTION
  372.   TPort.
  373.     {}
  374.    setROP2(mode:Integer):Integer;
  375.      begin
  376.        setROP2 := WinProcs.setROP2(context, mode)
  377.      end;
  378.  
  379.  
  380.   FUNCTION
  381.   TPort.
  382.    {}
  383.   mapMode :Integer;
  384.     begin
  385.       mapMode := getMapMode(context)
  386.     end;
  387.  
  388.   PROCEDURE
  389.   TPort.
  390.    {}
  391.   setMapMode(mm :Integer);
  392.     begin
  393.       WinProcs.setMapMode(context, mm)
  394.     end;
  395.  
  396.   PROCEDURE
  397.   TPort.
  398.    {}
  399.   textExtents(s :pChar; var width, height :Word);
  400.     var
  401.       size :Longint;
  402.     begin
  403.       size := getTextExtent(context, s, strLen(s));
  404.       height := hiWord(size);
  405.       width  := loWord(size)
  406.     end;
  407.  
  408.  
  409. END.